-
Notifications
You must be signed in to change notification settings - Fork 2k
Anthropic UsageAccessor #2068
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Anthropic UsageAccessor #2068
Conversation
ilayaperumalg
commented
Jan 14, 2025
- This PR introduces Usage accessor to retrieve the usage metadata fields from the ChatCompletion Usage response metadata - Having UsageAccessor would help enable the clients getting access to the entire metadata instead of pre-defined set of metadata
- Add utility method to UsageUtils to parseLong value from the metadata value object
- Add tests
- This PR introduces Usage accessor to retrieve the usage metadata fields from the ChatCompletion Usage response metadata
- Having UsageAccessor would help enable the clients getting access to the entire metadata instead of pre-defined set of metadata
- Add utility method to UsageUtils to parseLong value from the metadata value object
- Add tests
e06d9db to
ac32938
Compare
| } | ||
|
|
||
| @Override | ||
| public String toString() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be removed as this is implicit.
| return UsageUtils.parseLong(this.usage.get(CACHE_READ_INPUT_TOKENS)); | ||
| } | ||
|
|
||
| public Map<String, Object> getUsage() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename this to getUsageData()
| * | ||
| * @author Ilayaperumal Gopinathan | ||
| */ | ||
| public record AnthropicUsageAccessor(Map<String, Object> usage) implements Usage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be simplified to AnthropicUsage
| * | ||
| * @author Ilayaperumal Gopinathan | ||
| */ | ||
| public record AnthropicUsageAccessor(Map<String, Object> usage) implements Usage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the extensibility let's not make this record
| */ | ||
| public static Long parseLong(Object value) { | ||
| if (value == null) { | ||
| return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If null, return -1
|
Closing this PR as the design to return the 'native' usage classes with a method |